package com.patsnap.data.npd.dw.repository;

import com.patsnap.data.npd.dw.repository.impl.AdsJournalRepositoryImpl;
import com.patsnap.data.npd.dw.repository.impl.DwdJournalRepositoryImpl;
import com.patsnap.data.npd.dw.repository.impl.OdsJournalRepositoryImpl;
import lombok.Data;
import org.apache.ibatis.session.SqlSessionFactory;

import javax.sql.DataSource;
import java.util.Map;

@Data
public class DBOperator {

    OdsJournalRepository odsJournalRepo;

    DwdJournalRepository dwdJournalRepository;

    AdsJournalRepositoryImpl adsJournalRepository;

    Map<String, DataSource> dataSourceMap;

    public DBOperator() {
    }

    public DBOperator(SqlSessionFactory odsSqlSessionFactory,
                      SqlSessionFactory dwSqlSessionFactory,
                      SqlSessionFactory adsSqlSessionFactory,
                      SqlSessionFactory saSqlSessionFactory) {
        if (null != odsSqlSessionFactory) {
            odsJournalRepo = new OdsJournalRepositoryImpl(odsSqlSessionFactory);
        }

        if (adsSqlSessionFactory != null) {
            adsJournalRepository = new AdsJournalRepositoryImpl(adsSqlSessionFactory);
        }

        if (dwSqlSessionFactory != null) {
            dwdJournalRepository = new DwdJournalRepositoryImpl(dwSqlSessionFactory);
        }
    }
}
